package com.xpgk.mvc.bsendMessage;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.jfinal.plugin.activerecord.Model;

public class ModelKit {
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static <T extends Model, K> Map<K, T> listToMap(List<T> list, String columnKey, Class<K> keyType)
	{
		if(list == null || list.isEmpty())
		{
			return new HashMap<K, T>();
		}
		Map<K, T> map = new HashMap<K, T>();
		for (T t : list) 
		{
			Object val = t.get(columnKey);
			if(val != null)
			{
				map.put((K)val, t);
			}
		}
		return map;
	}
	
	@SuppressWarnings({"rawtypes","unchecked"})
	public static <T extends Model<T>,K> Set<K> getToSet(List<T> list,String column,Class K){
		if(list == null || list.isEmpty())
		{
			return new HashSet<K>();
		}
		Set<K> set = new HashSet<K>();
		for(T t:list){
			set.add((K)t.get(column));
		}
		return set;
	}
	
}
